package com.cff.shorturl.service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.cff.shorturl.service.imp.GenService;
import com.cff.shorturl.service.imp.RedirectService;

public class ServiceFactory {
	
	static Map<String,ServiceType> mapping = new ConcurrentHashMap<>();
	static{
		mapping.put("gen", ServiceType.GEN);
	}
	public static Service createService(String data){
		ServiceType type = mapping.getOrDefault(data, ServiceType.REDIRECT);
		switch(type){
		case GEN:
			return new GenService();
		default:
			return new RedirectService();
		}
	}
	
	private enum ServiceType {  
		GEN(1),
		REDIRECT(2);
	    int value = 0;
	    ServiceType(int value) {
	        this.value = value;
	    }
	    public int getValue() {
	        return value;
	    }
	}  
}
